home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
DISHOW.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-25
|
9KB
|
301 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: dishow.c
// Title: Data File I/O Library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains code to display the contents of data files.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <di.h>
//----------------------------------------------------------------------------
// Mapping of file types
//----------------------------------------------------------------------------
DIOTYPE adiotype[] =
{
{ DFT_RANDOM, "RAND", "Random Access Data" },
{ DFT_DELETED, "DEL ", "Deleted file" },
{ DFT_BLOCK, "BLCK", "Blocked Data" },
{ DFT_ISAM_DATA, "ISAM", "ISAM Data" },
{ DFT_ISAM0, "ISM0", "ISAM Index Level 0" },
{ DFT_ISAM1, "ISM1", "ISAM Index Level 1" },
{ DFT_ISAM2, "ISM2", "ISAM Index Level 2" },
{ DFT_ISAM3, "ISM3", "ISAM Index Level 3" },
{ DFT_ISAM4, "ISM4", "ISAM Index Level 4" },
{ DFT_ISAM5, "ISM5", "ISAM Index Level 5" },
{ DFT_ISAM6, "ISM6", "ISAM Index Level 6" },
{ DFT_ISAM7, "ISM7", "ISAM Index Level 7" },
{ DFT_ISAM8, "ISM8", "ISAM Index Level 8" },
{ DFT_ISAM9, "ISM9", "ISAM Index Level 9" },
{ DFT_ISAMA, "ISMA", "ISAM Index Level A" },
{ DFT_ISAMB, "ISMB", "ISAM Index Level B" },
{ DFT_ISAMC, "ISMC", "ISAM Index Level C" },
{ DFT_ISAMD, "ISMD", "ISAM Index Level D" },
{ DFT_ISAME, "ISME", "ISAM Index Level E" },
{ DFT_ISAMF, "ISMF", "ISAM Index Level F" },
{ DFT_ISAMF, "ISMF", "ISAM Index Level F" },
{ DFT_ISAM_RECNO, "IREC", "ISAM Record # Index" },
{ 0, NULL, NULL }
};
//----------------------------------------------------------------------------
// Prototypes
//----------------------------------------------------------------------------
static BOOL FN_L DioShowDirLong(PDATADIR, SIZET);
static BOOL FN_L DioShowDirShort(PDATADIR, SIZET);
static BOOL FN_L DioShowHeader(PDATAHDR);
//----------------------------------------------------------------------------
// Description: Show all directory entries in file.
// Parameters: pcsz File name.
// fLong If true, show in long format. Otherwise display
// in short format.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioShow(PCSZ pcsz, BOOL fLong)
{
CHAR szName[DFH_NAME+1];
HPF hpf;
DATAHDR hdr;
DATADIR dir;
LONG lTotal = 0;
SIZET cDir;
BOOL fResult = FALSE;
BOOL fUser;
Output("File '%s':\n", pcsz);
if (HIUSHORT(pcsz))
{
if (!DioOpenPhysical(pcsz, &hpf, FALSE))
return FALSE;
fUser = FALSE;
}
else
{
hpf = LOUSHORT(pcsz);
Assert(hpf >= 0 && hpf < MAX_PHYSICAL_FILES);
Assert(di.physical[hpf].fUsed);
fUser = TRUE;
}
if (!DioHeaderRead(hpf, &hdr))
goto ERROR_EXIT;
if (fLong)
{
if (!DioShowHeader(&hdr))
goto ERROR_EXIT;
}
else
{
memcpy(szName,0,sizeof(szName));
memcpy(szName,hdr.chName,sizeof(hdr.chName));
Output("\n%s\n\n", szName);
Output(" # Name Type Flags Base Length\n");
Output(" -------------------------------------------------------------------------\n");
}
for (cDir = 0; cDir < (SIZET)hdr.usDirectoryEntries; ++cDir)
{
if (!DioDirRead(hpf, cDir, &dir))
goto ERROR_EXIT;
if (dir.chName[0])
lTotal += (LONG)dir.flen;
if (fLong)
{
if (!DioShowDirLong(&dir, cDir))
goto ERROR_EXIT;
}
else
{
if (!DioShowDirShort(&dir, cDir))
goto ERROR_EXIT;
}
while (KbdReady())
if (KbdChar() == '\x1B')
{
Output("\nAborted!\n");
goto ERROR_EXIT;
}
}
Output("%u/%u entries. %ld bytes.\n\n",
hdr.usDirectoryUsed, hdr.usDirectoryEntries, lTotal);
fResult = TRUE;
ERROR_EXIT:
if (!fUser)
DioClosePhysical(hpf);
return fResult;
}
//----------------------------------------------------------------------------
// Description: Show file directory entry in long format
// Parameters: pdir Directory data.
// cDir Directory offset
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
static BOOL FN_L DioShowDirLong(PDATADIR pdir, SIZET cDir)
{
CHAR szName[DFD_NAME+1];
PSZ pszType = "Unknown File Type";
SIZET i;
for (i = 0; adiotype[i].pszShort; ++i)
if (adiotype[i].usType == pdir->usType)
{
pszType = adiotype[i].pszLong;
break;
}
Output("*** Directory %u ***\n", cDir);
memcpy(szName,0,sizeof(szName));
memcpy(szName,pdir->chName,sizeof(pdir->chName));
Output(" Name: %s\n", szName);
Output(" Type: %s\n", pszType);
Output(" Block size: %u\n", pdir->usBlockSize);
Output(" Base: %ld\n", pdir->fbase);
Output(" Length: %ld\n", pdir->flen);
Output(" Flags: 0x%08lX\n", pdir->fl);
Output(" CRC: 0x%08lX\n", pdir->crc);
Output(" Data CRC: 0x%08lX\n", pdir->crcData);
Output(" User Version: %04X\n", pdir->usUserVersion);
Output(" User data: ");
for (i = 0; i < sizeof(pdir->bUser); ++i)
{
Output("%02X ", pdir->bUser[i]);
if (((i+1) % 16) == 0)
Output("\n ");
}
Output("\n");
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Show all directory entries in file in abbreviate mode.
// Parameters: pdir Directory data.
// cDir Directory offset
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
static BOOL FN_L DioShowDirShort(PDATADIR pdir, SIZET cDir)
{
CHAR szName[DFD_NAME+1];
Output(" %03d: ", cDir);
if (pdir->chName[0])
{
PSZ pszType = "????";
SIZET i;
for (i = 0; adiotype[i].pszShort; ++i)
if (adiotype[i].usType == pdir->usType)
{
pszType = adiotype[i].pszShort;
break;
}
if (pdir->usType == DFT_DELETED)
strcpy(szName, "*** DELETED! ***");
else
{
memcpy(szName,0,sizeof(szName));
memcpy(szName, pdir->chName,sizeof(pdir->chName));
}
Output("%-*s %4s %08lX %8ld %8ld\n",
sizeof(pdir->chName), szName,
pszType, pdir->fl, pdir->fbase, pdir->flen);
}
else
Output("*** NOT USED ***\n");
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Show file header data
// Parameters: phdr Header data to display.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
static BOOL FN_L DioShowHeader(PDATAHDR phdr)
{
CHAR szName[DFH_NAME+1];
struct tm *tm;
SIZET i;
CHAR szAppId[DFH_APP_ID+1];
Output("*** Header ***\n");
memcpy(szName,0,sizeof(szName));
memcpy(szName,phdr->chName,sizeof(phdr->chName));
Output(" Name: %s\n", szName);
Output(" ID: 0x%08lX\n", phdr->lId);
Output(" Version: %u.%02u\n", (phdr->usVersion >> 8), (phdr->usVersion & 0x00FF));
Output(" Directories: %u of %u directories used.\n",phdr->usDirectoryUsed, phdr->usDirectoryEntries);
Output(" Flags: 0x%08lX\n", phdr->fl);
tm = localtime((time_t *)&phdr->timetCreated);
Output(" Created: %2d:%02d:%02d %2d/%02d/%4d.\n",
tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
tm = localtime((time_t *)&phdr->timetModified);
Output(" Last Modified: %2d:%02d:%02d %2d/%02d/%4d.\n",
tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
Output(" CRC: 0x%08lX\n", phdr->crc);
Output(" User Version: %04X\n", phdr->usUserVersion);
memcpy(szAppId, phdr->szAppId, 4);
szAppId[4] = '\0';
Output(" Application ID: %s\n", szAppId);
Output(" User data: ");
for (i = 0; i < sizeof(phdr->bUser); ++i)
{
Output("%02X ", phdr->bUser[i]);
if (((i+1) % 16) == 0)
Output("\n" " ");
}
Output("\n");
return TRUE;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------